package com.ssy.lingxi.workflow.controller;

import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.workflow.api.model.vo.request.ProcessMemberRoleVO;
import com.ssy.lingxi.workflow.api.model.vo.request.ProcessRemoveMemberRoleVO;
import com.ssy.lingxi.workflow.service.IProcessRoleService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 流程步骤关联的会员自定义角色相关接口
 * @author 万宁
 * @version 2.0.0
 * @date 2020-04-28
 */
@RestController
@RequestMapping("/workflow/role")
public class ProcessMemberRoleController {
    @Resource
    private IProcessRoleService processRoleService;

    /**
     * 查询流程定义，关联流程步骤与会员自定义角色
     * @param processMemberRoleVO 接口参数
     * @return 操作结果
     */
    @RequestMapping("/update")
    public Wrapper<Void> updateInsertProcessAsync(@RequestBody @Valid ProcessMemberRoleVO processMemberRoleVO) {
        synchronized (ProcessMemberRoleController.class) {
            processRoleService.updateInsertMemberRoleAuth(processMemberRoleVO);
            return Wrapper.success();
        }
    }

    /**
     * 从关联的流程步骤中，移除会员自定义角色
     * @param processRemoveMemberRoleVO 接口参数
     * @return 异步操作结果
     */
    @RequestMapping("/remove")
    public Wrapper<Void> removeMemberRoleAsync(@RequestBody @Valid ProcessRemoveMemberRoleVO processRemoveMemberRoleVO) {
        synchronized (ProcessMemberRoleController.class) {
            processRoleService.removeMemberRole(processRemoveMemberRoleVO);
            return Wrapper.success();
        }
    }
}
